﻿using ACGN.Application.ProPictures;
using ACGN.Application.ProPictures.Dtos;
using ACGN.Core.Models;
using ACGN.Core.Repository;
using ACGN.Mvc.Controllers;
using ACGN.MVC.Models.ProPicturess;
using AutoMapper;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace ACGN.MVC.Areas.Admin.Controllers
{
    [Area("Admin")]
    public class ProPictureController : BaseController
    {
        private readonly ILogger<ProPictureController> _logger;
        private readonly IRepository<ProPicture, int> _repository;
        private readonly IProPictureService _proPictureService;
        private readonly IMapper _mapper;
        private readonly IRepository<Product, int> _productRepository;

        public ProPictureController(ILogger<ProPictureController> logger,
            IRepository<ProPicture, int> repository,
            IProPictureService proPictureService,
            IMapper mapper,
            IRepository<Product, int> productRepository)
        {
            _logger = logger;
            _repository = repository;
            _proPictureService = proPictureService;
            _mapper = mapper;
            _productRepository = productRepository;
        }
        public async Task<IActionResult> Index()
        {
            ViewBag.ProTypeList = new MultiSelectList(await _productRepository.GetAllListAsync(), "PId", "PName");
            return View();
        }
        public async Task<IActionResult> List(ProPictureInputDto input)
        {
            var proPic = await _proPictureService.GetPageResult(input);
            return Json(ListResult(_mapper.Map<List<ProPictureViewModel>>(proPic.Data), proPic.TotalCount));
        }
    }
}
